/**
 * related to baiduMap.ui
 * 
 * @Author : 2037630@163.com
 * @Timestamp : 2017-05-09
 */
var Controller = require("core/controller");
var log = require("util/log");
var constant = require('config/constant');
var page=sm("do_Page");
var do_Device=sm("do_Device")
var net = require("util/net");
var baiduNav = require("util/map");
var notify = sm("do_Notification");
Controller({
	config:{
		name:"map",
		header:{
			title:""
		}
	},
	mapping : {
		"tv_address.text":"tv_address"
	},
	ui:{
		map:"baiduMapView",
		tv_address:"tv_address",
		
	},
	data : {
		deviceName:"",
		custName:"",
		tv_address:eval('(' + page.getData().geolocation + ')').detailAddress||'',
		Markers :[{
		    "id" : "id1",
		    "latitude" : "",
		    "longitude" : "",
		    "url" : "source://image/app/location.png",
//		    "info" : eval('(' + page.getData().geolocation + ')').detailAddress||''
		    "popup":false
		}],
		titleInfo:""
	},
	event:{
		'btn_daohang':{
			'touch':function(){
				log.info(566)
			if (do_Device.getInfo().OS == "android") {
					this.navigateZouni()
				}else {
					notify.toast("IOS导航正在加紧研发中... ...")
			}
			}
		},
		'bg_add':{
			'touch':function(){
				var zoomLevel_add = this.ui.map.zoomLevel + 1;
				this.ui.map.zoomLevel = zoomLevel_add;
			}
		},
		'bg_decre':{
			'touch':function(){
				var zoomLevel_reduce= this.ui.map.zoomLevel - 1;
				this.ui.map.zoomLevel = zoomLevel_reduce;
			}
		}
	},
	methods:{
		showLocation:function(){
			this.ui.map.setCenter({
			    latitude : this.data.Markers[0].latitude,
			    longitude :this.data.Markers[0].longitude
			});
			this.ui.map.addMarkers({
			    data : this.data.Markers,
			    info:"5666"
			})
			
		},
		navigateZouni:function(){
			baiduNav.navigate({
				latitude : this.data.Markers[0].latitude,
				longitude :this.data.Markers[0].longitude
			})
		},
//		getDeviceName:function(){
//			if (do_Device.getInfo().OS == "android") {
//				this.data.deviceName="ANDROID"
//			}else {
//				this.data.deviceName="IOS"
//			}
//		}
	},
	loaded:function (data){
		
//		this.getDeviceName()
		log.info(909,this.data.deviceName)
		var location=data.geolocation;
		log.info("cccc")
		log.info(location)
		var realData=eval('(' + location + ')')
		this.data.custName=realData.custName
		log.info(typeof realData)
//		log.info(realData.address)
		this.data.Markers[0].latitude=realData.mapInfo.lat
		this.data.Markers[0].longitude=realData.mapInfo.lng
		this.updateHeader(realData.custName)
		this.showLocation()
		
	}
})
